﻿<Window x:Class="vkGroupExplorer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:entity="clr-namespace:for7raid.vk"
                    xmlns:local="clr-namespace:for7raid.vkGroupExplorer"
        Title="vkGroupExplorer" Height="700" Width="800">
    <Window.Resources>
        <SolidColorBrush 
                                    x:Key="{x:Static SystemColors.HighlightBrushKey}"  
                                    Color="Gray" />
        <Style TargetType="ListBox">
            <Style.Triggers>
                <Trigger Property="ItemsSource" Value="{x:Null}">
                    <Setter Property="Template" Value="{StaticResource WaitControlTemplate}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="ListBoxItem">
            <Setter Property="IsSelected" Value="{Binding Path=(local:MainWindowViewModel.IsSelected)}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=(local:MainWindowViewModel.IsSelected)}" Value="true">
                    <Setter Property="TextBlock.Foreground" Value="Black"/>
                </DataTrigger>

            </Style.Triggers>
        </Style>
        <Style TargetType="DataGrid">
            <Style.Triggers>
                <Trigger Property="ItemsSource" Value="{x:Null}">
                    <Setter Property="Template" Value="{StaticResource WaitControlTemplate}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="DataGridRow">
            <Setter Property="IsSelected" Value="{Binding Path=(local:MainWindowViewModel.IsSelected)}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=(local:MainWindowViewModel.IsSelected)}" Value="true">
                    <Setter Property="TextBlock.Foreground" Value="Black"/>
                </DataTrigger>

            </Style.Triggers>
        </Style>
    </Window.Resources>
    <!--<Menu>
        <MenuItem Header="Сервис">
            <MenuItem Header="Обновить список групп"/>
            <Separator/>
            <MenuItem IsCheckable="True" Header="Открывать ссылки в строенном браузере"/>

        </MenuItem>
    </Menu>-->
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="0" />
            <ColumnDefinition Width="0" />
        </Grid.ColumnDefinitions>

        <GridSplitter Grid.Column="1" Width="3" VerticalAlignment="Stretch" Background="Gray" ShowsPreview="True"/>

        <TabControl Grid.RowSpan="3">
            <TabItem Header="По группам">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <GridSplitter Grid.Row="1" Height="3" HorizontalAlignment="Stretch" Background="Gray" ShowsPreview="True" />

                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>

                        <ListBox Margin="3" ItemsSource="{Binding Groups}" SelectionMode="Extended" Name="groups" HorizontalContentAlignment="Center"
                         ItemTemplate="{StaticResource GroupThumbTemplate}" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <UniformGrid/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>

                        </ListBox>
                        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
                            <Button Content="Выбрать все" Margin="3" CommandParameter="{Binding Groups}" Command="local:MainWindowViewModel.SelectAllCommand"/>
                            <Button Content="Отменить выбор" Margin="3" CommandParameter="{Binding Groups}" Command="local:MainWindowViewModel.SelectNoneCommand"/>
                            <TextBlock Text="Выберите город:" VerticalAlignment="Center" ToolTip="Выберите город после загрузки пользователей" Margin="30,3,3,3"/>
                            <ComboBox Margin="3" Width="250" DisplayMemberPath="Name" TextSearch.TextPath="Name" VirtualizingStackPanel.IsVirtualizing="True"
                              ItemsSource="{Binding Cities}" SelectedItem="{Binding SelectedCity, Mode=OneWayToSource}"/>
                        </StackPanel>
                        <Button Grid.Row="1" Content="Найти общих пользователей"  Margin="3" HorizontalAlignment="Right"
                        Command="local:MainWindowViewModel.FindUserIntersectionCommand"/>
                    </Grid>

                    <Grid Grid.Row="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>

                        <ListBox Grid.Row="0"  Margin="3" Name="users"
                         ItemsSource="{Binding UserIntersection}" ItemTemplate="{StaticResource UserItemTemplate}"
                                ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VirtualizingStackPanel.IsVirtualizing="True">
                        </ListBox>
                        <StatusBar Grid.Row="1">
                            <StatusBarItem>
                                <TextBlock Text="{Binding ElementName=groups, Path=SelectedItems.Count, StringFormat=Выбрано групп: {0}}"/>
                            </StatusBarItem>
                            <StatusBarItem>
                                <TextBlock Text="{Binding ElementName=users, Path=Items.Count, StringFormat=Найдено пользователей: {0}}"/>
                            </StatusBarItem>
                        </StatusBar>
                    </Grid>
                </Grid>

            </TabItem>

            <TabItem Header="Человек в группе">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <Button Content="Добавить группу" Grid.Column="0" Margin="3" Width="110" Command="local:MainWindowViewModel.AddGroupsCommand"/>
                    <!--<ListBox Grid.Row="1" Margin="3" ItemsSource="{Binding Groups}" SelectionMode="Extended" HorizontalContentAlignment="Center"
                         ItemTemplate="{StaticResource GroupThumbTemplate}" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <UniformGrid/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                    </ListBox>-->
                    <DataGrid Grid.Row="1" Margin="3" ItemsSource="{Binding Groups}" CanUserAddRows="False" CanUserSortColumns="True" AutoGenerateColumns="False">
                        <DataGrid.Columns>
                          
                            <!--<DataGridTemplateColumn>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate >
                                        <CheckBox IsChecked="{Binding Path=(local:MainWindowViewModel.IsSelected), Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>-->
                            <DataGridTextColumn Header="Имя группы" Binding="{Binding Name}" IsReadOnly="True" MaxWidth="300"/>
                            <DataGridCheckBoxColumn Header="В группе" Binding="{Binding Path=(local:MainWindowViewModel.IsUserMemeber)}" IsReadOnly="True" CanUserSort="False"/>
                        </DataGrid.Columns>
                    </DataGrid>

                    <Button Content="Добавить человека" Grid.Column="1" Margin="3" Width="110" Command="local:MainWindowViewModel.AddUsersCommand"/>
                    <ListBox Grid.Column="1" Grid.Row="1" Margin="3" SelectedItem="{Binding SelectedUser}"
                         ItemsSource="{Binding Friends}" ItemTemplate="{StaticResource UserItemTemplate}"
                                ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VirtualizingStackPanel.IsVirtualizing="True">
                    </ListBox>

                    <StackPanel Grid.Row="2" Margin="3" Orientation="Horizontal" HorizontalAlignment="Left">
                        <Button Content="Выбрать все" Margin="3" CommandParameter="{Binding Groups}" Command="local:MainWindowViewModel.SelectAllCommand"/>
                        <Button Content="Отменить выбор" Margin="3" CommandParameter="{Binding Groups}" Command="local:MainWindowViewModel.SelectNoneCommand"/>
                    </StackPanel>
                    <Button Grid.Row="2" Grid.Column="1" Content="Найти группы"  Margin="3" HorizontalAlignment="Right"
                        Command="local:MainWindowViewModel.FindUserGroupsCommand"/>

                    <StatusBar Grid.Row="3">
                        <StatusBarItem>
                            <TextBlock Text="{Binding ElementName=groups, Path=Items.Count, StringFormat=Всего групп: {0}}"/>
                        </StatusBarItem>
                        <StatusBarItem>
                            <TextBlock Text="{Binding ElementName=groups, Path=SelectedItems.Count, StringFormat=Выбрано групп: {0}}"/>
                        </StatusBarItem>
                        <StatusBarItem>
                            <TextBlock Text="{Binding Path=FindUserGroupsCount, StringFormat=Найдено групп: {0}}"/>
                        </StatusBarItem>
                    </StatusBar>
                </Grid>
            </TabItem>
        </TabControl>

        <!--<WebBrowser Grid.Column="2" Grid.RowSpan="3" Source="http://vk.com/" ObjectForScripting="{x:Null}"/>-->
    </Grid>

</Window>
